package com.liuqi.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liuqi.common.base.service.AbstractSimpleEntityService;
import com.liuqi.iot.bean.dto.DeviceDataDTO;
import com.liuqi.iot.bean.query.DeviceDataQuery;
import com.liuqi.iot.domain.entity.DeviceDataEntity;
import com.liuqi.iot.domain.mapper.DeviceDataMapper;
import com.liuqi.iot.service.DeviceDataEntityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 设备数据服务实现
 * 不直接使用
 * @author Coder Generator 2025-03-22 15:29:32 
 **/
@Service
public class DeviceDataServiceImpl extends AbstractSimpleEntityService<DeviceDataEntity, DeviceDataDTO, DeviceDataMapper, DeviceDataQuery> implements DeviceDataEntityService {
    /**
     * 查询对象转QueryWrapper
     *
     * @param query 查询对象
     * @return 包含有对应条件的QueryWrapper
     */
    @Override
    protected QueryWrapper<DeviceDataEntity> queryToWrapper(DeviceDataQuery query) {
        return this.createQueryWrapper()
                .eq(StringUtils.isNotBlank(query.getId()), "id", query.getId())
                .in(null != query.getIds(), "id", query.getIds())
                .eq(StringUtils.isNotBlank(query.getDeviceCode()), "device_code", query.getDeviceCode())
                .ge(null != query.getBeginTime(), "timestamp", query.getBeginTime())
                .le(null != query.getEndTime(), "timestamp", query.getEndTime())
                .in(null != query.getParamCodes(), "param_code", query.getParamCodes())
                .orderByDesc("create_time");
    }

    @Override
    public void batchUpsert(List<DeviceDataDTO> list) {
        if (CollectionUtils.isEmpty(list)) {
            return;
        }

        baseMapper.batchUpsert(list);
    }
}